package com.example.myspringframework.core.convert.support;

import com.example.myspringframework.core.convert.converter.GenericConverter;

import java.util.Collections;
import java.util.Set;

/**
 * 字符串转Boolean类型的转换器
 */
public class StringToBooleanConverter implements GenericConverter {
    /**
     * 获取对应的ConvertiblePair
     */
    @Override
    public Set<ConvertiblePair> getConvertibleTypes() {
        return Collections.singleton(new ConvertiblePair(String.class, Boolean.class));
    }

    /**
     * 具体的转换操作
     */
    @Override
    public Object convert(Object source, Class<?> sourceType, Class<?> targetType) {
        return Boolean.valueOf((String) source);
    }
}
